package model;

import lock.*;

public class BubbleSort implements SortType{

	
	private final Boolean sorted;
	private final Lock swapLock;
	
	public BubbleSort(){
		this.sorted = false;
		this.swapLock = new ConcreteLock(false);
	}
	
	@Override
	public void sort(final Buffer<Integer> toBeSorted) {
		// TODO bubbleSort with threads!
		
		while(!sorted){
			new Thread(new BubbleSorter(toBeSorted)).start();
		}
	}
	
	
	private final class BubbleSorter implements Runnable {
		private final Buffer<Integer> toBeSorted;

		private BubbleSorter(final Buffer<Integer> toBeSorted) {
			this.toBeSorted = toBeSorted;
		}

		@Override
		public void run() {
			swapLock.lock();
			swap();
			swapLock.unlock();
		}
		
		private void swap() {
			
		}
		
	}

}
